#!/bin/bash -e
container_name="imeasy"
image_name="imeasy:latest"
port=5000
env="Production"
config="/app/Configuration" 
quartzDB="/app/quartz.db"
wwwroot="/app/wwwroot"
uploads="/app/uploads"


echo ""
echo -e "\033[1;34m[信息] 开始构建程序\033[0m"
echo ""


cd "$(dirname "$0")"
cd ..

echo "正在构建生产环境"

echo "正在初始化构建镜像'$container_name'"
docker build --no-cache -t $image_name  -f  Dockerfile ../
if [[ $(docker ps -a --format '{{.Names}}' | grep -w "$container_name") ]]; then
   echo "容器'$container_name'已存在"
   echo "正在停止容器....."
   docker stop $container_name
   echo "正在删除容器....."
   docker rm $container_name
fi
echo "正在初始化新容器 '$container_name'..."
# docker run -dp $port:8080  --restart=unless-stopped -v /root/assets/configuration:$config /root/assets/quartz.db:quartzDB --name $container_name -e ASPNETCORE_ENVIRONMENT=$env -e TZ=Asia/Shanghai  $image_name 
docker run -dp \
  $port:8080 \
  --restart=unless-stopped \
  -v /root/assets/configuration:$config \
  -v /root/assets/quartz.db:$quartzDB \
  -v /root/assets/wwwroot:$wwwroot \
  -v /root/assets/uploads:$uploads \
  --name $container_name \
  -e ASPNETCORE_ENVIRONMENT=$env \
  -e TZ=Asia/Shanghai \
  $image_name

echo -e "\033[1;34m生产环境容器初始化成功\033[0m"